package edu.hwadee.BEIS.repository;

import edu.hwadee.BEIS.entity.SchoolBasicInfor;
import edu.hwadee.BEIS.entity.SchoolCondition;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Set;

public interface SchoolConditionRepository extends JpaRepository<SchoolCondition, Integer> {

	/**
	 * 通过SchoolBasicInfor查询学校的办学情况
	 * @param schoolBasicInfor
	 * @param county
	 * @param city
	 * @return
	 */
	SchoolCondition findOneBySchoolBasicIsAndCountyAuditStatusIsAndCityAuditStatusIsOrderByModifyTimeDesc(SchoolBasicInfor schoolBasicInfor, Short county, Short city);

	Set<SchoolCondition> findBySchoolBasicInAndCountyAuditStatusIsAndCityAuditStatusIsOrderByModifyTimeDesc(Set<SchoolBasicInfor> schoolBasicInfors, Short county, Short city);

	/*
	 * 根据办学条件的ID查询办学条件
	 */
	SchoolCondition findByConditionId(Integer conditionId);

	/*
	 * 根据学校基本信息查询办学条件，并按修改时间排序
	 */
	Page<SchoolCondition> findBySchoolBasicInOrderByModifyTimeDesc(Pageable pageable, Set<SchoolBasicInfor> schoolBasic);

	/*
	 * 根据学校基本信息和区县审核状态查询办学条件，并按修改时间排序
	 */
	Page<SchoolCondition> findBySchoolBasicInAndCountyAuditStatusIsOrderByModifyTimeDesc(Pageable pageable, Set<SchoolBasicInfor> schoolBasic, Short countyAuditStatus);

	/*
	 * 根据办学条件的学校基本信息的belongID或区县审核状态为通过查询办学条件，并按照修改时间排序，去重
	 */
	Page<SchoolCondition> findDistinctBySchoolBasic_BelongIdOrCountyAuditStatusOrderByModifyTimeDesc(Pageable pageable,String belongId, Short countyAuditStatus);

	/*
	 * 根据办学条件表的学校基本信息的belongID或区县审核状态为通过，同时根据市局审核状态查询办学条件，并按照修改时间排序，去重
	 */
	Page<SchoolCondition> findDistinctBySchoolBasic_BelongIdAndCityAuditStatusOrCountyAuditStatusAndCityAuditStatusOrderByModifyTimeDesc(Pageable pageable,String belongId, Short cityAuditStatus1,Short countyAuditStatus,Short cityAuditStatus2);

}